<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<h3 class="page-header">
				<span>投票项设置</span>
			</h3>
		</div>
		<!-- /.col-lg-12 -->
	</div>
	<!-- /.row -->

	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					<button class="btn btn-success" onclick="show_detail_ori();" style="float: left">增加</button>
					<!--<form id="zjdailyCard" name="zjdailyCard" method="get" class="placedInline">-->
					<!--<button type="submit" formaction="{:U('User/Praise/download')}" formmethod="post" class="btn btn-sm btn-success dword-size">数据导出</button>-->
					<!--</form>-->
					<button class="btn btn-warning" onclick="download({$praiseid});" style="float: left;margin-left:5px">作品导出</button>
					<button class="btn btn-warning" onclick="download_comment({$praiseid});" style="float: left;margin-left:5px">评论导出</button>

					<select class="form-control" style="margin-left:30%;width:200px;" name="status" id="status">
						<option value="0" <?php $status = I("get.status", 0, '');if($status == 0){ echo " selected";}?>>全部</option>
						<option value="1" <?php $status = I("get.status", 0, '');if($status == 1){ echo " selected";}?>>已审核</option>
						<option value="9" <?php $status = I("get.status", 0, '');if($status == 9){ echo " selected";}?>>待审核</option>
					</select>

				</div>
				<!-- /.panel-heading -->
				<div class="panel-body">
					<div class="table-responsive">
						<table class="table table-bordered">
							<thead>
							<tr>
								<!--<th><input type="checkbox" data-action="checkboxAll"></th>-->
								<th width="10%">投票项</th>
								<th width="10%">名称</th>
								<th width="10%">状态</th>
								<th width="30%">简介</th>
								<th width="10%">结果</th>
								<th width="10%">图片</th>
								<th width="20%">操作</th>
							</tr>
							</thead>
							<tbody>
							<foreach name='datas' item='data' >
								<tr>
									<!--<td><input type="checkbox" data-action="checkboxOnce" name="praises[]" value="{$data['id']}" form="praiseOpera"></td>-->
									<td>{$data['grade']}</td>
									<td>{$data['show_name']}</td>
									<td><?php if($data['status'] == 1){
											echo "正常";}else{
												echo "待审核";
											}?></td>
									<td>{$data['contract']}</td>
									<td>{$data['share']}</td>
									<td><img class="thumbnail-sm" src="{$data['pic']}" alt="无" style="width:300px"></td>
									<td>
										<button type="button" onclick="edit_detail({$data['id']})" class="btn btn-success">编辑</button>
										<button type="button" onclick="item_delete({$data['id']})" class="btn btn-danger">删除</button>
										<br/><br/>
										<button type="button" onclick="item_through({$data['id']})" class="btn btn-info">审核通过</button>
										<br/><br/>
										<button type="button" onclick="item_comment({$data['id']})" class="btn btn-info">查看评论</button>
									</td>
								</tr>
							</foreach>
							</tbody>
						</table>
					</div>
					<!-- /.table-responsive -->
				</div>
				<!-- /.panel-body -->
			</div>
			<!-- /.panel -->
		</div>
		<!-- /.col-lg-6 -->
	</div>
	<nav>
		<ul class="pagination">
			<php>
				$uri = $_SERVER['REQUEST_URI'];
				$str_p = strpos( $uri, 'page' );
				$str_q = false;
				if( $str_p != false ){
				//$str_q = strpos( $uri, "&", $str_p );
				$str_q = strlen($uri);
				}
				if( $str_p != false && $str_q != false ){
				$uri = substr_replace( $uri, "", $str_p, $str_q - $str_p );
				}
				$str_p = strrpos( $uri, "?" );
				if( $str_p == strlen($uri) - 1 ){
				$uri = substr_replace( $uri, "", $str_p, 1 );
				}
				$str_p = strrpos( $uri, "&" );
				if( $str_p == strlen($uri) - 1 ){
				$uri = substr_replace( $uri, "", $str_p, 1 );
				}
			</php>
			<if condition="$page['pre'] gt 0 ">
				<li>
					<a href="{:implode(array( $uri, '&', 'page', '=', $page['pre']) )}" aria-label="Previous">
						<span aria-hidden="true">&laquo;</span>
					</a>
				</li>
			</if>
			<for start="1" end=":intval( $page['count'] ) ">
				<li class="{$page['curren']==$i ? 'active':''}"><a href="{:implode(array( $uri, '&', 'page', '=', $i) )}">{$i}</a></li>
			</for>
			<if condition="$page['next'] lt ( $page['count'] )">
				<li>
					<a href="{:implode(array( $uri, '&', 'page', '=', $page['next']) )}" aria-label="Next">
						<span aria-hidden="true">&raquo;</span>
					</a>
				</li>
			</if>
		</ul>
	</nav>
	<!-- /.row -->
</div>
<!-- /#page-wrapper -->
<div class="modal fade netMsgModal" id="netMsgModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="change_detail()">&times;</button>
				<h4 class="modal-title">新建投票项</h4>
			</div>
			<div class="modal-body">
				<form class="form" action="{:U('User/praiseeat/item_edit')}" method="post" enctype="multipart/form-data">
					<input type="hidden" name="item_id" id="item_id" value="">
					<input type="hidden" name="praise_id" value="<?php echo $praiseid;?>">
					<div class="form-group">
						<label>名称</label>
						<input class="form-control" name="show_name" id="show_name" value="">
					</div>
					<div class="form-group">
						<label>简介</label>
						<input class="form-control" name="contract" id="contract" value="">
					</div>
					<div class="form-group" id="show_pic" style="display: none">
						<img width="100%" height="200px" src="" alt=" " id="add_pic" class="thumbnail preview" data-preview="uploadFile">
						<!-- <input type="hidden" name="picurl" value="{$praise['picurl']}" data-set="uploadFile"> -->
						<input name="picurl" type="file" data-action="uploadFile" style="margin-top: -10px;margin-bottom: 10px;" id="input_file">
					</div>
					<div class="form-group" id="show_pic1" style="display: none">
						<img src=""  class="thumbnail" width="100%" height="320px" data-preview="uploadFile1" id="change_pic">
						<input type="hidden" name="picurl1" id="change_pic_value" value="" data-set="uploadFile1">
						<input type="file" class="changePic" data-action="uploadFile1"  style="margin-top: -10px;margin-bottom: 10px;" id="input_file1">
					</div>
					<div class="modal-footer">
						<button type="submit" class="btn btn-success">提交</button>
						<button type="button" class="btn btn-default" data-dismiss="modal" onclick="change_detail();">关闭</button>
					</div>
				</form>
			</div>

		</div><!-- /.modal-content -->
	</div>
</div>


<import type="js" file="common" basepath="/Public/js" />
<script type="text/javascript" src="/Public/js/common.cursor.js"></script>
<script type="text/javascript" src="/Public/js/common.upload.js"></script>
<script type="text/javascript">
	common.upload.img.init();
	$("#status").change(function(){
		window.location = "/User/praiseeat/items?status="+$("#status").val();
	});
	common.cursor.preview.init({
		div: '.thumbnail-sm'
	});
	function show_detail(){
		$("#netMsgModal").modal( "show" );
	}
	function edit_detail(id){
		$.ajax({
			url:"/User/praiseeat/item_get",
			data:{id:id},
			dataType:'json',
			success:function(res){
				$("#item_id").val(res['id']);
				$("#show_name").val(res['show_name']);
				$("#contract").val(res['contract']);
				if(res['pic'] == "" || res['pic'] == undefined || res['pic'] == null) {
					$("#change_pic").attr("src","");
					$("#change_pic_value").val("");
					$("#input_file").val("");
					$("#input_file1").val("");
					$("#show_pic").css("display","block");
					$("#show_pic1").css("display","none");
				}else{
					$("#input_file").val("");
					$("#input_file1").val("");
					$("#change_pic").attr("src",res['pic']);
					$("#change_pic_value").val(res['pic']);
					$("#show_pic1").css("display","block");
					$("#show_pic").css("display","none");
				}
				show_detail();
			}
		});
	}
	function change_detail(){
		$("#item_id").val("");
		$("#show_name").val("");
		$("#contract").val("");
		$("#change_pic").attr("src","");
		$("#change_pic_value").val("");
		$("#input_file").val("");
		$("#input_file1").val("");
		$("#show_pic").css("display","block");
		$("#show_pic1").css("display","none");
	}
	function show_detail_ori(){
		change_detail();
		show_detail();
	}
	function item_delete(id){
		$.ajax({
			url:'/User/praiseeat/item_delete',
			data:{item_id:id},
			type:'get',
			success:function(res){
				window.location.reload();
			}
		});
	}
    function item_through(id){
        $.ajax({
            url:'/User/praiseeat/item_through',
            data:{item_id:id},
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
    }
    function item_comment(id){
        window.location = "/User/praiseeat/item_comment?item_id="+id;
        return false;
    }
	function download(id){
        window.location = "/User/praiseeat/download?praise_id="+id;
	}
    function download_comment(id){
        window.location = "/User/praiseeat/download_comment?praise_id="+id;
    }
</script>
